package com.gg.user.gguser.service.impl;

import com.gg.user.gguser.dao.GgSearchMapper;
import com.gg.user.gguser.dataobject.GgInformationDataobject;
import com.gg.user.gguser.dataobject.GgSearchDataobject;
import com.gg.user.gguser.service.GgSearchService;
import com.gg.vo.return_format;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author yangxinlei
 * @date 2020/4/28
 */
@Service
public class GgSearchServiceImpl implements GgSearchService {

    @Autowired
    private GgSearchMapper ggSearchMapper;

    @Override
    public Object getSearch(HttpServletResponse response, HttpServletRequest request, String q, Integer page, Integer pageNumber) throws Exception {
        try {
            Integer getSearchCount = ggSearchMapper.getSearchCount(q);
            List<GgSearchDataobject> getSearchCountList =   ggSearchMapper.getSearch(q,(page-1)*pageNumber, pageNumber);
            return return_format.return_format_All(0,return_format.return_format_data_map(page, (int) Math.ceil(getSearchCount/pageNumber),pageNumber,getSearchCount,getSearchCountList),"");
        }catch (Exception e){
            return return_format.return_format_error(100002,"服务器报错！");
        }
    }
}
